/*
 * 
 * Created on Jul 27, 2005
 */
package com.wgo.precise.client.ui.view.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.eclipse.ui.views.properties.IPropertyDescriptor;

import com.wgo.precise.client.ui.model.AbstractPropertySpesification;
import com.wgo.precise.client.ui.model.PropertySetWrapper;
import com.wgo.precise.client.ui.model.RequirementWrapper;
import com.wgo.precise.common.VO.Requirement;

/**
 * 
 * @author Petter L. H. Eide
 * @version $Id: RequirementPropertySource.java,v 1.2 2006-01-30 21:52:32 petterei Exp $
 */
public class RequirementPropertySource extends ModelItemPropertySource {

    private String requirementCategory = Requirement.class.getSimpleName() + " details";
    
    public RequirementPropertySource(RequirementWrapper node) {
        super(node);
    }

    @Override
    public IPropertyDescriptor[] getPropertyDescriptors() {
        List<IPropertyDescriptor> descs = new ArrayList<IPropertyDescriptor>();
        descs.addAll(Arrays.asList(super.getPropertyDescriptors()));
        Collection<AbstractPropertySpesification> defs = new ArrayList<AbstractPropertySpesification>();
        defs.addAll(RequirementWrapper.getSortedRequirementSpesifications());
        IPropertyDescriptor[] staticDescriptors = createPropertyDescriptors(defs, requirementCategory);
        descs.addAll(Arrays.asList(staticDescriptors));
//        RequirementPlugin.log(getClass(), "Number of properties bla bla.. : " + ((RequirementWrapper)getItem()).getUserDefinedTypes().size());
        ((RequirementWrapper)getItem()).verifyProperties();
//        RequirementPlugin.log(getClass(), "Number of properties bla bla.. : " + ((RequirementWrapper)getItem()).getUserDefinedTypes().size());
        // for the spesific type:
        Collection<AbstractPropertySpesification> modelDefs; 
        for (PropertySetWrapper set : ((RequirementWrapper)getItem()).getPropertyDefinitionSets()) {
        	modelDefs = set.getAbstractPopertyDefinitions();
            IPropertyDescriptor[] descriptors = createPropertyDescriptors(modelDefs, set.getSimpleName());
            descs.addAll(Arrays.asList(descriptors));
        }
        return descs.toArray(new IPropertyDescriptor[descs.size()]);
    }

}
